package com.webapi.core.model.dto;

import java.util.ArrayList;
import java.util.List;

import com.webapi.common.utils.DateUtils;
import com.webapi.core.model.common.OrderStatus;
import com.webapi.core.model.persist.Order;

public class OrderDto extends BaseDto {

    private String cd;
    private String agentCode;
    private OrderStatus status;
    private List<TicketDto> tickets = new ArrayList<TicketDto>();
    private PayDto pay;

    public String getCd() {
        return cd;
    }

    public void setCd(String cd) {
        this.cd = cd;
    }

    public String getAgentCode() {
		return agentCode;
	}

	public void setAgentCode(String agentCode) {
		this.agentCode = agentCode;
	}

	public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
    }

    public List<TicketDto> getTickets() {
        return tickets;
    }

    public void setTickets(List<TicketDto> tickets) {
        this.tickets = tickets;
    }

    public PayDto getPay() {
        return pay;
    }

    public void setPay(PayDto pay) {
        this.pay = pay;
    }
    
    public static List<OrderDto> valueOf(List<Order> orders) {
    	List<OrderDto> dtos = new ArrayList<OrderDto>();
    	for (Order order : orders) {
    		dtos.add(valueOf(order));
    	}
    	return dtos;
    }
    
    public static OrderDto valueOf(Order order) {
        OrderDto dto = new OrderDto();
        dto.setId(order.getId());
        dto.setStatus(order.getStatus());
        dto.setCd(order.getCd());
        dto.setAgentCode(order.getAgentCode());
        dto.setCreateTime(DateUtils.date2stringLong(order.getCreateTime()));
        dto.setPay(PayDto.valueOf(order.getPay()));
        dto.setTickets(TicketDto.valueOf(order.getTickets()));
        return dto;
    }

	@Override
	public String toString() {
		return "OrderDto [cd=" + cd + ", agentCode=" + agentCode + ", status="
				+ status + ", tickets=" + tickets + ", pay=" + pay
				+ ", getId()=" + getId() + ", getCreateTime()="
				+ getCreateTime() + "]";
	}

}
